<?php

/**
 * This is the model class for table "xman_notebook".
 *
 * The followings are the available columns in table 'xman_notebook':
 * @property integer $notebook_id
 * @property string $notebook_name
 * @property integer $notebook_category_id
 * @property string $notebook_content
 * @property string $notebook_created_date
 * @property string $notebook_updated_date
 * @property string $notebook_deleted_date
 * @property integer $notebook_posted_by_user_id
 *
 * The followings are the available model relations:
 * @property User $notebookPostedByUser
 * @property NotebookCategory $notebookCategory
 * @property NotebookUser[] $notebookUsers
 */
class Notebook extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Notebook the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_notebook';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('notebook_name, notebook_category_id, notebook_content, notebook_posted_by_user_id', 'required'),
			array('notebook_category_id, notebook_posted_by_user_id', 'numerical', 'integerOnly'=>true),
			array('notebook_name', 'length', 'max'=>50),
			array('notebook_content', 'length', 'max'=>5000),
			array('notebook_created_date, notebook_updated_date, notebook_deleted_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('notebook_id, notebook_name, notebook_category_id, notebook_content, notebook_created_date, notebook_updated_date, notebook_deleted_date, notebook_posted_by_user_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'notebookPostedByUser' => array(self::BELONGS_TO, 'User', 'notebook_posted_by_user_id'),
			'notebookCategory' => array(self::BELONGS_TO, 'NotebookCategory', 'notebook_category_id'),
			'notebookUsers' => array(self::HAS_MANY, 'NotebookUser', 'notebook_user_notebook_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'notebook_id' => 'Notebook',
			'notebook_name' => 'Notebook Name',
			'notebook_category_id' => 'Notebook Category',
			'notebook_content' => 'Notebook Content',
			'notebook_created_date' => 'Notebook Created Date',
			'notebook_updated_date' => 'Notebook Updated Date',
			'notebook_deleted_date' => 'Notebook Deleted Date',
			'notebook_posted_by_user_id' => 'Notebook Posted By User',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('notebook_id',$this->notebook_id);
		$criteria->compare('notebook_name',$this->notebook_name,true);
		$criteria->compare('notebook_category_id',$this->notebook_category_id);
		$criteria->compare('notebook_content',$this->notebook_content,true);
		$criteria->compare('notebook_created_date',$this->notebook_created_date,true);
		$criteria->compare('notebook_updated_date',$this->notebook_updated_date,true);
		$criteria->compare('notebook_deleted_date',$this->notebook_deleted_date,true);
		$criteria->compare('notebook_posted_by_user_id',$this->notebook_posted_by_user_id);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}